#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int n , m;
const int N = 5010;
struct node
{
    int p , x;
}a[N];
bool cmp(node &a ,node &b)
{
    return a.p < b.p;
}
int main()
{
    cin >> n >> m;
    for(int i = 1;i <= m;i ++) cin >> a[i].p >> a[i].x;
    sort(a + 1 , a + 1 + m ,cmp);
    int sum = 0 , ret = 0;
    for(int i = 1;i <= m;i++)
    {
        int t = min(a[i].x , n - sum);
        ret += t * a[i].p;
        sum += t;
    }
    cout << ret << endl;

    return 0;
}